/*
 * Created by the DBAccessor generator.
 * Programmer: Lennart Martens
 * Date: 08/08/2012
 * Time: 21:02:33
 */
package com.compomics.proteocloud.db.accessor;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import com.compomics.util.db.interfaces.Deleteable;
import com.compomics.util.db.interfaces.Persistable;
import com.compomics.util.db.interfaces.Retrievable;
import com.compomics.util.db.interfaces.Updateable;

/*
 * CVS information:
 *
 * $Revision: 1.4 $
 * $Date: 2007/07/06 09:41:53 $
 */

/**
 * This class is a generated accessor for the Omssahit table.
 *
 * @author DBAccessor generator class (Lennart Martens).
 */
public class OmssahitTableAccessor implements Deleteable, Retrievable, Updateable, Persistable {

	/**
	 * This variable tracks changes to the object.
	 */
	protected boolean iUpdated = false;

	/**
	 * This variable can hold generated primary key columns.
	 */
	protected Object[] iKeys = null;

	/**
	 * This variable represents the contents for the 'omssahitid' column.
	 */
	protected long iOmssahitid = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'l_spectrumid' column.
	 */
	protected long iL_spectrumid = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'hitsetnumber' column.
	 */
	protected long iHitsetnumber = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'e_value' column.
	 */
	protected Number iE_value = null;


	/**
	 * This variable represents the contents for the 'p_value' column.
	 */
	protected Number iP_value = null;


	/**
	 * This variable represents the contents for the 'charge' column.
	 */
	protected long iCharge = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'mass' column.
	 */
	protected long iMass = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'theomas' column.
	 */
	protected long iTheomas = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'pepstart' column.
	 */
	protected String iPepstart = null;


	/**
	 * This variable represents the contents for the 'pepstop' column.
	 */
	protected String iPepstop = null;


	/**
	 * This variable represents the contents for the 'sequence' column.
	 */
	protected String iSequence = null;


	/**
	 * This variable represents the contents for the 'protein' column.
	 */
	protected String iProtein = null;


	/**
	 * This variable represents the contents for the 'pep' column.
	 */
	protected Number iPep = null;


	/**
	 * This variable represents the contents for the 'qvalue' column.
	 */
	protected Number iQvalue = null;


	/**
	 * This variable represents the key for the 'omssahitid' column.
	 */
	public static final String OMSSAHITID = "OMSSAHITID";

	/**
	 * This variable represents the key for the 'l_spectrumid' column.
	 */
	public static final String L_SPECTRUMID = "L_SPECTRUMID";

	/**
	 * This variable represents the key for the 'hitsetnumber' column.
	 */
	public static final String HITSETNUMBER = "HITSETNUMBER";

	/**
	 * This variable represents the key for the 'e_value' column.
	 */
	public static final String E_VALUE = "E_VALUE";

	/**
	 * This variable represents the key for the 'p_value' column.
	 */
	public static final String P_VALUE = "P_VALUE";

	/**
	 * This variable represents the key for the 'charge' column.
	 */
	public static final String CHARGE = "CHARGE";

	/**
	 * This variable represents the key for the 'mass' column.
	 */
	public static final String MASS = "MASS";

	/**
	 * This variable represents the key for the 'theomas' column.
	 */
	public static final String THEOMAS = "THEOMAS";

	/**
	 * This variable represents the key for the 'pepstart' column.
	 */
	public static final String PEPSTART = "PEPSTART";

	/**
	 * This variable represents the key for the 'pepstop' column.
	 */
	public static final String PEPSTOP = "PEPSTOP";

	/**
	 * This variable represents the key for the 'sequence' column.
	 */
	public static final String SEQUENCE = "SEQUENCE";

	/**
	 * This variable represents the key for the 'protein' column.
	 */
	public static final String PROTEIN = "PROTEIN";

	/**
	 * This variable represents the key for the 'pep' column.
	 */
	public static final String PEP = "PEP";

	/**
	 * This variable represents the key for the 'qvalue' column.
	 */
	public static final String QVALUE = "QVALUE";




	/**
	 * Default constructor.
	 */
	public OmssahitTableAccessor() {
	}

	/**
	 * This constructor allows the creation of the 'OmssahitTableAccessor' object based on a set of values in the HashMap.
	 *
	 * @param	aParams	HashMap with the parameters to initialize this object with.
	 *		<i>Please use only constants defined on this class as keys in the HashMap!</i>
	 */
	public OmssahitTableAccessor(HashMap aParams) {
		if(aParams.containsKey(OMSSAHITID)) {
			this.iOmssahitid = ((Long)aParams.get(OMSSAHITID)).longValue();
		}
		if(aParams.containsKey(L_SPECTRUMID)) {
			this.iL_spectrumid = ((Long)aParams.get(L_SPECTRUMID)).longValue();
		}
		if(aParams.containsKey(HITSETNUMBER)) {
			this.iHitsetnumber = ((Long)aParams.get(HITSETNUMBER)).longValue();
		}
		if(aParams.containsKey(E_VALUE)) {
			this.iE_value = (Number)aParams.get(E_VALUE);
		}
		if(aParams.containsKey(P_VALUE)) {
			this.iP_value = (Number)aParams.get(P_VALUE);
		}
		if(aParams.containsKey(CHARGE)) {
			this.iCharge = ((Long)aParams.get(CHARGE)).longValue();
		}
		if(aParams.containsKey(MASS)) {
			this.iMass = ((Long)aParams.get(MASS)).longValue();
		}
		if(aParams.containsKey(THEOMAS)) {
			this.iTheomas = ((Long)aParams.get(THEOMAS)).longValue();
		}
		if(aParams.containsKey(PEPSTART)) {
			this.iPepstart = (String)aParams.get(PEPSTART);
		}
		if(aParams.containsKey(PEPSTOP)) {
			this.iPepstop = (String)aParams.get(PEPSTOP);
		}
		if(aParams.containsKey(SEQUENCE)) {
			this.iSequence = (String)aParams.get(SEQUENCE);
		}
		if(aParams.containsKey(PROTEIN)) {
			this.iProtein = (String)aParams.get(PROTEIN);
		}
		if(aParams.containsKey(PEP)) {
			this.iPep = (Number)aParams.get(PEP);
		}
		if(aParams.containsKey(QVALUE)) {
			this.iQvalue = (Number)aParams.get(QVALUE);
		}
		this.iUpdated = true;
	}


	/**
	 * This constructor allows the creation of the 'OmssahitTableAccessor' object based on a resultset
	 * obtained by a 'select * from Omssahit' query.
	 *
	 * @param	aResultSet	ResultSet with the required columns to initialize this object with.
	 * @exception	SQLException	when the ResultSet could not be read.
	 */
	public OmssahitTableAccessor(ResultSet aResultSet) throws SQLException {
		this.iOmssahitid = aResultSet.getLong("omssahitid");
		this.iL_spectrumid = aResultSet.getLong("l_spectrumid");
		this.iHitsetnumber = aResultSet.getLong("hitsetnumber");
		this.iE_value = (Number)aResultSet.getObject("e_value");
		this.iP_value = (Number)aResultSet.getObject("p_value");
		this.iCharge = aResultSet.getLong("charge");
		this.iMass = aResultSet.getLong("mass");
		this.iTheomas = aResultSet.getLong("theomas");
		this.iPepstart = (String)aResultSet.getObject("pepstart");
		this.iPepstop = (String)aResultSet.getObject("pepstop");
		this.iSequence = (String)aResultSet.getObject("sequence");
		this.iProtein = (String)aResultSet.getObject("protein");
		this.iPep = (Number)aResultSet.getObject("pep");
		this.iQvalue = (Number)aResultSet.getObject("qvalue");

		this.iUpdated = true;
	}


	/**
	 * This method returns the value for the 'Omssahitid' column
	 * 
	 * @return	long	with the value for the Omssahitid column.
	 */
	public long getOmssahitid() {
		return this.iOmssahitid;
	}

	/**
	 * This method returns the value for the 'L_spectrumid' column
	 * 
	 * @return	long	with the value for the L_spectrumid column.
	 */
	public long getL_spectrumid() {
		return this.iL_spectrumid;
	}

	/**
	 * This method returns the value for the 'Hitsetnumber' column
	 * 
	 * @return	long	with the value for the Hitsetnumber column.
	 */
	public long getHitsetnumber() {
		return this.iHitsetnumber;
	}

	/**
	 * This method returns the value for the 'E_value' column
	 * 
	 * @return	Number	with the value for the E_value column.
	 */
	public Number getE_value() {
		return this.iE_value;
	}

	/**
	 * This method returns the value for the 'P_value' column
	 * 
	 * @return	Number	with the value for the P_value column.
	 */
	public Number getP_value() {
		return this.iP_value;
	}

	/**
	 * This method returns the value for the 'Charge' column
	 * 
	 * @return	long	with the value for the Charge column.
	 */
	public long getCharge() {
		return this.iCharge;
	}

	/**
	 * This method returns the value for the 'Mass' column
	 * 
	 * @return	long	with the value for the Mass column.
	 */
	public long getMass() {
		return this.iMass;
	}

	/**
	 * This method returns the value for the 'Theomas' column
	 * 
	 * @return	long	with the value for the Theomas column.
	 */
	public long getTheomas() {
		return this.iTheomas;
	}

	/**
	 * This method returns the value for the 'Pepstart' column
	 * 
	 * @return	String	with the value for the Pepstart column.
	 */
	public String getPepstart() {
		return this.iPepstart;
	}

	/**
	 * This method returns the value for the 'Pepstop' column
	 * 
	 * @return	String	with the value for the Pepstop column.
	 */
	public String getPepstop() {
		return this.iPepstop;
	}

	/**
	 * This method returns the value for the 'Sequence' column
	 * 
	 * @return	String	with the value for the Sequence column.
	 */
	public String getSequence() {
		return this.iSequence;
	}

	/**
	 * This method returns the value for the 'Protein' column
	 * 
	 * @return	String	with the value for the Protein column.
	 */
	public String getProtein() {
		return this.iProtein;
	}

	/**
	 * This method returns the value for the 'Pep' column
	 * 
	 * @return	Number	with the value for the Pep column.
	 */
	public Number getPep() {
		return this.iPep;
	}

	/**
	 * This method returns the value for the 'Qvalue' column
	 * 
	 * @return	Number	with the value for the Qvalue column.
	 */
	public Number getQvalue() {
		return this.iQvalue;
	}

	/**
	 * This method sets the value for the 'Omssahitid' column
	 * 
	 * @param	aOmssahitid	long with the value for the Omssahitid column.
	 */
	public void setOmssahitid(long aOmssahitid) {
		this.iOmssahitid = aOmssahitid;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'L_spectrumid' column
	 * 
	 * @param	aL_spectrumid	long with the value for the L_spectrumid column.
	 */
	public void setL_spectrumid(long aL_spectrumid) {
		this.iL_spectrumid = aL_spectrumid;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Hitsetnumber' column
	 * 
	 * @param	aHitsetnumber	long with the value for the Hitsetnumber column.
	 */
	public void setHitsetnumber(long aHitsetnumber) {
		this.iHitsetnumber = aHitsetnumber;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'E_value' column
	 * 
	 * @param	aE_value	Number with the value for the E_value column.
	 */
	public void setE_value(Number aE_value) {
		this.iE_value = aE_value;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'P_value' column
	 * 
	 * @param	aP_value	Number with the value for the P_value column.
	 */
	public void setP_value(Number aP_value) {
		this.iP_value = aP_value;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Charge' column
	 * 
	 * @param	aCharge	long with the value for the Charge column.
	 */
	public void setCharge(long aCharge) {
		this.iCharge = aCharge;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Mass' column
	 * 
	 * @param	aMass	long with the value for the Mass column.
	 */
	public void setMass(long aMass) {
		this.iMass = aMass;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Theomas' column
	 * 
	 * @param	aTheomas	long with the value for the Theomas column.
	 */
	public void setTheomas(long aTheomas) {
		this.iTheomas = aTheomas;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Pepstart' column
	 * 
	 * @param	aPepstart	String with the value for the Pepstart column.
	 */
	public void setPepstart(String aPepstart) {
		this.iPepstart = aPepstart;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Pepstop' column
	 * 
	 * @param	aPepstop	String with the value for the Pepstop column.
	 */
	public void setPepstop(String aPepstop) {
		this.iPepstop = aPepstop;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Sequence' column
	 * 
	 * @param	aSequence	String with the value for the Sequence column.
	 */
	public void setSequence(String aSequence) {
		this.iSequence = aSequence;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Protein' column
	 * 
	 * @param	aProtein	String with the value for the Protein column.
	 */
	public void setProtein(String aProtein) {
		this.iProtein = aProtein;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Pep' column
	 * 
	 * @param	aPep	Number with the value for the Pep column.
	 */
	public void setPep(Number aPep) {
		this.iPep = aPep;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Qvalue' column
	 * 
	 * @param	aQvalue	Number with the value for the Qvalue column.
	 */
	public void setQvalue(Number aQvalue) {
		this.iQvalue = aQvalue;
		this.iUpdated = true;
	}



	/**
	 * This method allows the caller to delete the data represented by this
	 * object in a persistent store.
	 *
	 * @param   aConn Connection to the persitent store.
	 */
	public int delete(Connection aConn) throws SQLException {
		PreparedStatement lStat = aConn.prepareStatement("DELETE FROM omssahit WHERE omssahitid = ?");
		lStat.setLong(1, iOmssahitid);
		int result = lStat.executeUpdate();
		lStat.close();
		return result;
	}


	/**
	 * This method allows the caller to read data for this
	 * object from a persistent store based on the specified keys.
	 *
	 * @param   aConn Connection to the persitent store.
	 */
	public void retrieve(Connection aConn, HashMap aKeys) throws SQLException {
		// First check to see whether all PK fields are present.
		if(!aKeys.containsKey(OMSSAHITID)) {
			throw new IllegalArgumentException("Primary key field 'OMSSAHITID' is missing in HashMap!");
		} else {
			iOmssahitid = ((Long)aKeys.get(OMSSAHITID)).longValue();
		}
		// In getting here, we probably have all we need to continue. So let's...
		PreparedStatement lStat = aConn.prepareStatement("SELECT * FROM omssahit WHERE omssahitid = ?");
		lStat.setLong(1, iOmssahitid);
		ResultSet lRS = lStat.executeQuery();
		int hits = 0;
		while(lRS.next()) {
			hits++;
			iOmssahitid = lRS.getLong("omssahitid");
			iL_spectrumid = lRS.getLong("l_spectrumid");
			iHitsetnumber = lRS.getLong("hitsetnumber");
			iE_value = (Number)lRS.getObject("e_value");
			iP_value = (Number)lRS.getObject("p_value");
			iCharge = lRS.getLong("charge");
			iMass = lRS.getLong("mass");
			iTheomas = lRS.getLong("theomas");
			iPepstart = (String)lRS.getObject("pepstart");
			iPepstop = (String)lRS.getObject("pepstop");
			iSequence = (String)lRS.getObject("sequence");
			iProtein = (String)lRS.getObject("protein");
			iPep = (Number)lRS.getObject("pep");
			iQvalue = (Number)lRS.getObject("qvalue");
		}
		lRS.close();
		lStat.close();
		if(hits>1) {
			throw new SQLException("More than one hit found for the specified primary keys in the 'omssahit' table! Object is initialized to last row returned.");
		} else if(hits == 0) {
			throw new SQLException("No hits found for the specified primary keys in the 'omssahit' table! Object is not initialized correctly!");
		}
	}
	/**
	 * This method allows the caller to obtain a basic select for this table.
	 *
	 * @return   String with the basic select statement for this table.
	 */
	public static String getBasicSelect(){
		return "select * from omssahit";
	}

	/**
	 * This method allows the caller to obtain all rows for this
	 * table from a persistent store.
	 *
	 * @param   aConn Connection to the persitent store.
	 * @return   ArrayList<OmssahitTableAccessor>   with all entries for this table.
	 */
	public static ArrayList<OmssahitTableAccessor> retrieveAllEntries(Connection aConn) throws SQLException {
		ArrayList<OmssahitTableAccessor>  entities = new ArrayList<OmssahitTableAccessor>();
		Statement stat = aConn.createStatement();
		ResultSet rs = stat.executeQuery(getBasicSelect());
		while(rs.next()) {
			entities.add(new OmssahitTableAccessor(rs));
		}
		rs.close();
		stat.close();
		return entities;
	}



	/**
	 * This method allows the caller to update the data represented by this
	 * object in a persistent store.
	 *
	 * @param   aConn Connection to the persitent store.
	 */
	public int update(Connection aConn) throws SQLException {
		if(!this.iUpdated) {
			return 0;
		}
		PreparedStatement lStat = aConn.prepareStatement("UPDATE omssahit SET omssahitid = ?, l_spectrumid = ?, hitsetnumber = ?, e_value = ?, p_value = ?, charge = ?, mass = ?, theomas = ?, pepstart = ?, pepstop = ?, sequence = ?, protein = ?, pep = ?, qvalue = ? WHERE omssahitid = ?");
		lStat.setLong(1, iOmssahitid);
		lStat.setLong(2, iL_spectrumid);
		lStat.setLong(3, iHitsetnumber);
		lStat.setObject(4, iE_value);
		lStat.setObject(5, iP_value);
		lStat.setLong(6, iCharge);
		lStat.setLong(7, iMass);
		lStat.setLong(8, iTheomas);
		lStat.setObject(9, iPepstart);
		lStat.setObject(10, iPepstop);
		lStat.setObject(11, iSequence);
		lStat.setObject(12, iProtein);
		lStat.setObject(13, iPep);
		lStat.setObject(14, iQvalue);
		lStat.setLong(15, iOmssahitid);
		int result = lStat.executeUpdate();
		lStat.close();
		this.iUpdated = false;
		return result;
	}


	/**
	 * This method allows the caller to insert the data represented by this
	 * object in a persistent store.
	 *
	 * @param   aConn Connection to the persitent store.
	 */
	public int persist(Connection aConn) throws SQLException {
		PreparedStatement lStat = aConn.prepareStatement("INSERT INTO omssahit (omssahitid, l_spectrumid, hitsetnumber, e_value, p_value, charge, mass, theomas, pepstart, pepstop, sequence, protein, pep, qvalue) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
		if(iOmssahitid == Long.MIN_VALUE) {
			lStat.setNull(1, 4);
		} else {
			lStat.setLong(1, iOmssahitid);
		}
		if(iL_spectrumid == Long.MIN_VALUE) {
			lStat.setNull(2, 4);
		} else {
			lStat.setLong(2, iL_spectrumid);
		}
		if(iHitsetnumber == Long.MIN_VALUE) {
			lStat.setNull(3, 4);
		} else {
			lStat.setLong(3, iHitsetnumber);
		}
		if(iE_value == null) {
			lStat.setNull(4, 3);
		} else {
			lStat.setObject(4, iE_value);
		}
		if(iP_value == null) {
			lStat.setNull(5, 3);
		} else {
			lStat.setObject(5, iP_value);
		}
		if(iCharge == Long.MIN_VALUE) {
			lStat.setNull(6, 4);
		} else {
			lStat.setLong(6, iCharge);
		}
		if(iMass == Long.MIN_VALUE) {
			lStat.setNull(7, 4);
		} else {
			lStat.setLong(7, iMass);
		}
		if(iTheomas == Long.MIN_VALUE) {
			lStat.setNull(8, 4);
		} else {
			lStat.setLong(8, iTheomas);
		}
		if(iPepstart == null) {
			lStat.setNull(9, 12);
		} else {
			lStat.setObject(9, iPepstart);
		}
		if(iPepstop == null) {
			lStat.setNull(10, 12);
		} else {
			lStat.setObject(10, iPepstop);
		}
		if(iSequence == null) {
			lStat.setNull(11, 12);
		} else {
			lStat.setObject(11, iSequence);
		}
		if(iProtein == null) {
			lStat.setNull(12, -1);
		} else {
			lStat.setObject(12, iProtein);
		}
		if(iPep == null) {
			lStat.setNull(13, 3);
		} else {
			lStat.setObject(13, iPep);
		}
		if(iQvalue == null) {
			lStat.setNull(14, 3);
		} else {
			lStat.setObject(14, iQvalue);
		}
		int result = lStat.executeUpdate();

		// Retrieving the generated keys (if any).
		ResultSet lrsKeys = lStat.getGeneratedKeys();
		ResultSetMetaData lrsmKeys = lrsKeys.getMetaData();
		int colCount = lrsmKeys.getColumnCount();
		iKeys = new Object[colCount];
		while(lrsKeys.next()) {
			for(int i=0;i<iKeys.length;i++) {
				iKeys[i] = lrsKeys.getObject(i+1);
			}
		}
		lrsKeys.close();
		lStat.close();
		// Verify that we have a single, generated key.
		if(iKeys != null && iKeys.length == 1 && iKeys[0] != null) {
			// Since we have exactly one key specified, and only
			// one Primary Key column, we can infer that this was the
			// generated column, and we can therefore initialize it here.
			iOmssahitid = ((Number) iKeys[0]).longValue();
		}
		this.iUpdated = false;
		return result;
	}

	/**
	 * This method will return the automatically generated key for the insert if 
	 * one was triggered, or 'null' otherwise.
	 *
	 * @return	Object[]	with the generated keys.
	 */
	public Object[] getGeneratedKeys() {
		return this.iKeys;
	}

}